/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gr.anagnosg.general.utils.text;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author anagnosg
 */
public class WordList {
    ArrayList words = new ArrayList();
    ArrayList charsList = new ArrayList(); 

    public ArrayList getCharsList() {
        return charsList;
    }

    public void setCharsList(ArrayList charsList) {
        this.charsList = charsList;
    }
    
    
   
    public ArrayList getWords() {
        return words;
    }

    public void setWords(ArrayList words) {
        this.words = words;
    }
    
    public int wordAt(int position){
        int index = 0 ;
        for(int i = 0 ; i < words.size() ; i++){
            Word w = (Word)words.get(i);
            if(w.startIndex<=position && w.endIndex>=position){
                index = i ;
            }
        }
        return index;
    
    }
    
    
    public int charCount(){
        int output = 0;
        for(int i =0;i<this.words.size();i++){
            output+=((Word)this.words.get(i)).text.length();
        
        }
        return output;
    }
    
   public int wordCount(){
       
       return this.words.size();
   }
   
   public  List generateCharList(){
       for(int i = 0 ; i < this.words.size() ; i++){
           Word w = (Word)this.words.get(i);
           char c[] = w.getText().toCharArray();
           for(int j = 0 ; j < c.length ; j++){
           
               this.charsList.add(c[j]+"");
           }
       }
       return this.charsList;
   }
   
   public boolean existsEmptyWord(){
       boolean output=false;
       System.out.println("check empy");
       for(int i = 0 ; i<this.words.size();i++){
           Word w = (Word)this.words.get(i);
           String text = w.getText();
           /*Pattern.compile("\\w+", Pattern.UNICODE_CHARACTER_CLASS)
            or embed a (?U) in the pattern:
            Pattern.compile("(?U)\\w+")
                //boolean output = false;
                List output = new ArrayList();
                Pattern pattern = Pattern.compile("[a-zA-Z]+");

                Matcher matcher = pattern.matcher(text);

                  while (matcher.find()) {*/
                   //}
       //Pattern.compile("\\w+", Pattern.UNICODE_CHARACTER_CLASS);
           //System.out.println(text);
           //output = text.matches("(\\s+)");
           output = Pattern.matches("(\\s*)", text);
           
           if(output){
           break;}
       }
       return output;
   }
   public void removeEmptyWords(){
       for(int i = 0 ; i<this.words.size();i++){
           Word w = (Word)this.words.get(i);
           String text = w.getText();
          
            boolean isEmpty =  Pattern.matches("(\\s*)", text);;
            this.words.remove(i);// remove(w);
       }
   }
   
   
   
}
